import pygame


class Ship:
    def __init__(self, ai_setting, screen):
        self.screen = screen
        self.ai_setting = ai_setting

        # 获取图片实例
        self.image = pygame.image.load('images/ship.bmp')
        # 获取图片范围
        self.rect = self.image.get_rect()
        # 获取游戏屏幕范围
        self.screen_rect = screen.get_rect()

        # 摆放图片位置
        self.rect.centerx = self.screen_rect.centerx
        # self.rect.centery = self.screen_rect.centery
        self.rect.bottom = self.screen_rect.bottom

        self.center = float(self.rect.centerx)
        # 移动标识
        self.moving_right = False
        self.moving_left = False

    def blitme(self):
        self.screen.blit(self.image, self.rect)

    def update(self):
        if self.moving_right:
            self.center += self.ai_setting.ship_speed_factor

        if self.moving_left:
            self.center -= self.ai_setting.ship_speed_factor

        self.rect.centerx = self.center
